﻿using ASP_NET.eTaxiWebReference;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASP_NET
{
    public partial class PPrincipal : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            FormsAuthentication.SignOut();
            FormsAuthentication.RedirectToLoginPage();
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            DateTime dia = new DateTime();

            foreach (DateTime dt in Calendar1.SelectedDates)
            {
                dia = new DateTime(dt.Year, dt.Month, dt.Day);
            }

            EtaxiSoapClient ws = new EtaxiSoapClient();
            DataBoleta[] boletas = ws.ListarBoletas();

            DataTable varDataTable = null;

            varDataTable = new DataTable();
            varDataTable.Columns.AddRange(new DataColumn[6] { 
                    new DataColumn("Matricula", typeof(string)),  
                    new DataColumn("Fecha", typeof(DateTime)),  
                    new DataColumn("Estado",typeof(string)),
                    new DataColumn("Importe",typeof(float)),
                    new DataColumn("KmsEntrada",typeof(int)),
                    new DataColumn("KmsSalida",typeof(int))
                });

            foreach (DataBoleta db in boletas) {

                if ((db.FecJornal.Year == dia.Year) && (db.FecJornal.Month == dia.Month) && (db.FecJornal.Day == dia.Day))
                {
                    lblSalida.Text = "";
                    varDataTable.Rows.Add(db.Matricula, db.FecJornal, db.Estado, db.Importe, db.KmEntrada, db.KmSalida);
                }
                else {
                    lblSalida.Text = "No hay ninguna boleta para este día.";
                }
            }


            GridViewBoletas.DataSource = varDataTable;
            GridViewBoletas.DataBind();
        
        }

    }
}